<template>
  <div>
    <van-nav-bar left-arrow
    @click-left="goleft"
    @click-right="goright">
        <template #left>
        <slot name="left"></slot>
        </template>
        <template #title>
        <slot name="title">
        </slot>
        </template>
        <template #right>
        <slot name="right"></slot>
        </template>
    </van-nav-bar>
  </div>
</template>

<script>
export default {
  methods: {
    goleft () {
      // 如果有历史记录则返回上一页，反之返回首页
      if (window.history.length > 1) {
        this.$router.go(-1)
      } else {
        this.$route.go('/layout')
      }
    },
    goright () {
      // 如果有历史记录则返回上一页，反之返回首页
      if (window.history.length > 1) {
        this.$router.go(-1)
      } else {
        this.$route.go('/layout')
      }
    }
  }
}
</script>

<style lang="less" scoped>
:deep(.van-icon ){
    color: black;
}
</style>
